home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 36.0 KB | 1,307 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWSemObj.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWSCPTBL_H
- #include "FWScptbl.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWSCPCOL_H
- #include "FWScpCol.h"
- #endif
-
- #ifndef FWSEMINT_H
- #include "FWSemInt.h"
- #endif
-
- #ifndef FWAPLEVT_H
- #include "FWAplEvt.h"
- #endif
-
- #ifndef FWDSCOPR_H
- #include "FWDscOpr.h"
- #endif
-
- #ifndef FWOBJSPC_H
- #include "FWObjSpc.h"
- #endif
-
- #ifndef FWSCPPRP_H
- #include "FWScpPrp.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef SLODFSTR_K
- #include "SLODFStr.k"
- #endif
-
- #ifndef SLODFSTR_H
- #include "SLODFStr.h"
- #endif
-
- #ifndef __AEOBJECTS__
- #include <AEObjects.h>
- #endif
-
- #ifndef __AEPACKOBJECT__
- #include <AEPackObject.h>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwsemevt
- #endif
-
- //========================================================================================
- // Template Instantiations
- //========================================================================================
-
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_MScriptable)
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_MScriptable)
-
- #ifdef FW_USE_TEMPLATE_PRAGMAS
-
- #pragma template_access public
- #pragma template FW_TOrderedCollection<FW_MScriptable>
- #pragma template FW_TOrderedCollectionIterator<FW_MScriptable>
-
- #endif
-
- FW_DEFINE_AUTO(FW_MScriptable)
- FW_DEFINE_AUTO(FW_CElementIterator)
-
- //========================================================================================
- // class FW_MScriptable
- //========================================================================================
-
- FW_DEFINE_CLASS_M0(FW_MScriptable)
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::FW_MScriptable
- //---------------------------------------------------------------------------------------
-
- FW_MScriptable::FW_MScriptable() :
- fDependents(NULL)
- {
- FW_END_CONSTRUCTOR
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::~FW_MScriptable
- //---------------------------------------------------------------------------------------
-
- FW_MScriptable::~FW_MScriptable()
- {
- FW_START_DESTRUCTOR
-
- if (fDependents)
- {
- FW_TOrderedCollectionIterator<FW_MScriptable> iter(fDependents);
- for (FW_MScriptable* i = iter.First(); iter.IsNotComplete(); i = iter.Next())
- {
- i->HandlePrimaryDeleted(this);
- }
- delete fDependents;
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetObjectClass
- //---------------------------------------------------------------------------------------
-
- ODDescType FW_MScriptable::GetObjectClass() const
- {
- return cObject;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetSpecifierForm
- //---------------------------------------------------------------------------------------
-
- ODDescType FW_MScriptable::GetSpecifierForm() const
- {
- return formAbsolutePosition;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetTokenType
- //---------------------------------------------------------------------------------------
-
- ODDescType FW_MScriptable::GetTokenType() const
- {
- return typeODFSemanticObject;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::HandleSemanticEvent
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::HandleSemanticEvent(Environment* ev,
- FW_CPart* part,
- AEKeyword eventClass,
- AEKeyword eventID,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- if (eventClass == kAECoreSuite)
- {
- switch (eventID)
- {
- case kAEClone:
- DoAEClone(ev, part, event, reply);
- break;
-
- case kAEClose:
- DoAEClose(ev, part, event, reply);
- break;
-
- case kAECountElements:
- DoAECountElements(ev, part, event, reply);
- break;
-
- case kAECreateElement:
- DoAECreateElement(ev, part, event, reply);
- break;
-
- case kAEDelete:
- DoAEDelete(ev, part, event, reply);
- break;
-
- case kAEDoObjectsExist:
- DoAEDoObjectsExist(ev, part, event, reply);
- break;
-
- case kAEGetClassInfo:
- DoAEGetClassInfo(ev, part, event, reply);
- break;
-
- case kAEGetData:
- DoAEGetData(ev, part, event, reply);
- break;
-
- case kAEGetDataSize:
- DoAEGetDataSize(ev, part, event, reply);
- break;
-
- case kAEGetEventInfo:
- DoAEGetEventInfo(ev, part, event, reply);
- break;
-
- case kAEMove:
- DoAEMove(ev, part, event, reply);
- break;
-
- case kAEOpen:
- DoAEOpen(ev, part, event, reply);
- break;
-
- case kAEPrint:
- DoAEPrint(ev, part, event, reply);
- break;
-
- case kAESave:
- DoAESave(ev, part, event, reply);
- break;
-
- case kAESetData:
- DoAESetData(ev, part, event, reply);
- break;
-
- default:
- DoSemanticEvent(ev, part, eventClass, eventID, event, reply);
- break;
- }
- }
- else
- DoSemanticEvent(ev, part, eventClass, eventID, event, reply);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::DoSemanticEvent
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::DoSemanticEvent(Environment* ev,
- FW_CPart* part,
- AEKeyword eventClass,
- AEKeyword eventID,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- FW_UNUSED(eventClass);
- FW_UNUSED(eventID);
- FW_UNUSED(event);
- FW_UNUSED(reply);
- FW_THROW(FW_XException(errAEEventNotHandled));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::DoAEClone
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::DoAEClone(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- FW_UNUSED(event);
- FW_UNUSED(reply);
- FW_THROW(FW_XException(errAEEventNotHandled));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::DoAEClose
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::DoAEClose(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- FW_UNUSED(event);
- FW_UNUSED(reply);
- FW_THROW(FW_XException(errAEEventNotHandled));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::DoAECountElements
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::DoAECountElements(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- reply.PutLongInteger(CountElements(ev, part, event.GetType(keyAEObjectClass)), keyAEResult);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::DoAECreate
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::DoAECreateElement(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- FW_UNUSED(event);
- FW_UNUSED(reply);
- FW_THROW(FW_XException(errAEEventNotHandled));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::DoAEDelete
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::DoAEDelete(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- FW_UNUSED(event);
- FW_UNUSED(reply);
- FW_THROW(FW_XException(errAEEventNotHandled));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::DoAEDoObjectsExist
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::DoAEDoObjectsExist(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- FW_UNUSED(event);
- FW_UNUSED(reply);
- FW_THROW(FW_XException(errAEEventNotHandled));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::DoAEGetClassInfo
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::DoAEGetClassInfo(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- FW_UNUSED(event);
- FW_UNUSED(reply);
- FW_THROW(FW_XException(errAEEventNotHandled));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::DoAEGetData
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::DoAEGetData(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_UNUSED(event);
- FW_CDesc objectSpecifier;
-
- BuildObjectSpecifier(ev, part, GetFrame(ev, part), objectSpecifier, GetSpecifierForm());
- reply.PutDataByDesc(objectSpecifier, keyAEResult);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::DoAEGetDataSize
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::DoAEGetDataSize(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- FW_UNUSED(event);
- FW_UNUSED(reply);
- FW_THROW(FW_XException(errAEEventNotHandled));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::DoAEGetEventInfo
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::DoAEGetEventInfo(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- FW_UNUSED(event);
- FW_UNUSED(reply);
- FW_THROW(FW_XException(errAEEventNotHandled));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::DoAEMove
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::DoAEMove(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- FW_UNUSED(event);
- FW_UNUSED(reply);
- FW_THROW(FW_XException(errAEEventNotHandled));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::DoAEOpen
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::DoAEOpen(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- FW_UNUSED(event);
- FW_UNUSED(reply);
- FW_THROW(FW_XException(errAEEventNotHandled));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::DoAEPrint
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::DoAEPrint(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- FW_UNUSED(event);
- FW_UNUSED(reply);
- FW_THROW(FW_XException(errAEEventNotHandled));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::DoAESave
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::DoAESave(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- FW_UNUSED(event);
- FW_UNUSED(reply);
- FW_THROW(FW_XException(errAEEventNotHandled));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::DoAESetData
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::DoAESetData(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- FW_UNUSED(event);
- FW_UNUSED(reply);
- FW_THROW(FW_XException(errAEEventNotHandled));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetFrame
- //---------------------------------------------------------------------------------------
-
- FW_CFrame* FW_MScriptable::GetFrame(Environment* ev, FW_CPart* part) const
- {
- return (part->GetLastActiveFrame(ev));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::Compare
- //---------------------------------------------------------------------------------------
-
- FW_Boolean FW_MScriptable::CompareScriptableObjects(Environment* ev,
- FW_CPart* part,
- ODDescType operation,
- const FW_CDesc& other) const
- {
- FW_Boolean result = FALSE;
-
- if (operation == kAEEquals &&
- part->GetSemanticInterface(ev)->TypeIsSemanticObject(ev, other.DescriptorType()))
- {
- FW_MScriptable* otherObject = ::FW_ExtractScriptableFromDesc(other);
- result = (this == otherObject);
- }
-
- return result;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetContainingObject
- //---------------------------------------------------------------------------------------
-
- FW_MScriptable* FW_MScriptable::GetContainingObject(Environment* ev,
- FW_CPart* part) const
- {
- FW_UNUSED(ev);
- FW_MScriptable* containingObject = FW_DYNAMIC_CAST(FW_MScriptable, part);
- FW_ASSERT(containingObject != NULL);
-
- containingObject->AcquireScriptable();
- return containingObject;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetContainedObject
- //---------------------------------------------------------------------------------------
-
- FW_Boolean FW_MScriptable::GetContainedObject(Environment* ev,
- FW_CPart* part,
- ODDescType desiredClass,
- ODDescType form,
- const FW_CDesc& selectionData,
- FW_CDesc& containedObjectToken)
- {
- FW_Boolean result = FALSE;
-
- if (desiredClass == cProperty)
- {
- ODDescType whichProperty;
-
- selectionData >> whichProperty;
-
- if (HasProperty(whichProperty))
- {
- FW_CPropertyDesignator* designator = FW_NEW(FW_CPropertyDesignator, (part, this, whichProperty));
- ::FW_InsertScriptableIntoDesc(designator, containedObjectToken);
- result = TRUE;
- }
- }
- else
- {
- FW_MScriptable* requestedObject = NULL;
-
- switch (form)
- {
- case formName:
- {
- FW_CString desiredName;
- selectionData.GetString(desiredName);
- requestedObject = GetElementByName(ev, part, desiredClass, desiredName);
- }
- break;
-
- case formRelativePosition:
- {
- ODDescType relativePosition;
-
- relativePosition = selectionData.GetEnumeratedType();
- requestedObject = GetAdjacentObject(ev, part, desiredClass, relativePosition);
- }
- break;
-
- case formRange:
- {
- FW_MScriptable* startObject = NULL;
- FW_MScriptable* stopObject = NULL;
-
- FW_CSemanticInterface* semInt = part->GetSemanticInterface(ev);
-
- FW_ASSERT(semInt);
-
- FW_CDesc rangeRecord;
- FW_CDesc objectSpec;
- FW_CDesc objectToken;
-
- selectionData.Coerce(typeAERecord, rangeRecord);
-
- rangeRecord.GetDataByDesc(objectSpec, keyAERangeStart);
- semInt->Resolve(ev, objectSpec, objectToken);
- startObject = semInt->GetScriptableFromToken(ev, objectToken);
-
- objectSpec.Clear();
- objectToken.Clear();
-
- rangeRecord.GetDataByDesc(objectSpec, keyAERangeStop);
- semInt->Resolve(ev, objectSpec, objectToken);
- stopObject = semInt->GetScriptableFromToken(ev, objectToken);
-
- requestedObject = GetElementsWithinRange(ev, part, desiredClass, startObject, stopObject);
- }
- break;
-
- case formUniqueID:
- break;
-
- case formAbsolutePosition:
- requestedObject = GetElementByAbsolutePosition(ev, part, desiredClass, selectionData);
- break;
-
- default:
- break;
- }
-
- if (requestedObject)
- {
- ::FW_InsertScriptableIntoDesc(requestedObject, containedObjectToken);
- result = TRUE;
- }
- }
- return result;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetElementByAbsolutePosition
- //---------------------------------------------------------------------------------------
-
- FW_MScriptable* FW_MScriptable::GetElementByAbsolutePosition(Environment* ev,
- FW_CPart* part,
- ODDescType desiredClass,
- const FW_CDesc& selectionData)
- {
- FW_MScriptable* requestedObject = NULL;
- ODDescType specifierType = selectionData.DescriptorType();
-
- if (specifierType == typeAbsoluteOrdinal)
- {
- switch (selectionData.GetAbsoluteOrdinal())
- {
- case kAEFirst:
- requestedObject = GetFirstElement(ev, part, desiredClass);
- break;
-
- case kAEMiddle:
- requestedObject = GetMiddleElement(ev, part, desiredClass);
- break;
-
- case kAELast:
- requestedObject = GetLastElement(ev, part, desiredClass);
- break;
-
- case kAEAny:
- requestedObject = GetAnyElement(ev, part, desiredClass);
- break;
-
- case kAEAll:
- requestedObject = GetAllElements(ev, part, desiredClass);
- break;
-
- default:
- break;
- }
-
- }
- else if (specifierType == typeLongInteger)
- {
- long objectIndex;
- selectionData >> objectIndex;
-
- if (objectIndex < 0)
- objectIndex += (CountElements(ev, part, desiredClass) + 1);
-
- requestedObject = GetElementByIndex(ev, part, desiredClass, objectIndex);
- }
-
- return requestedObject;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetElementByName: default implementation iterates through
- // contained elements of the specified type looking for a name match. Subclasses
- // may be able to optimize searching based on knowledge of content.
- //---------------------------------------------------------------------------------------
-
- FW_MScriptable* FW_MScriptable::GetElementByName(Environment* ev,
- FW_CPart* part,
- ODDescType desiredClass,
- const FW_CString& desiredName)
- {
- FW_CElementIterator* iter = NewElementIterator(ev, part, desiredClass);
-
- FW_VOLATILE(iter);
-
- FW_CDesc nameDesc;
- FW_CString nameString;
- FW_MScriptable* desiredObject = NULL;
-
- FW_TRY
- {
- for (FW_MScriptable* currentObject = iter->First();
- iter->IsNotComplete() && !desiredObject; currentObject = iter->Next())
- {
- if (currentObject->HasProperty(pName))
- {
- currentObject->GetProperty(ev, part, nameDesc, pName, typeChar);
- nameDesc.GetString(nameString);
-
- if (desiredName == nameString)
- desiredObject = currentObject;
- else
- nameDesc.Clear();
- }
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- delete iter;
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- delete iter;
-
- if (desiredObject)
- desiredObject->AcquireScriptable();
- return desiredObject;
- }
-
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::CountElements
- //---------------------------------------------------------------------------------------
-
- long FW_MScriptable::CountElements(Environment* ev,
- FW_CPart* part,
- ODDescType desiredClass)
- {
- unsigned long count = 0;
- FW_CElementIterator* iter = NewElementIterator(ev, part, desiredClass);
- FW_VOLATILE(iter);
-
- FW_TRY
- {
- for (iter->First(); iter->IsNotComplete(); iter->Next())
- count++;
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- delete iter;
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- delete iter;
-
- return count;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetElementByIndex
- //---------------------------------------------------------------------------------------
-
- FW_MScriptable* FW_MScriptable::GetElementByIndex(Environment* ev,
- FW_CPart* part,
- ODDescType desiredClass,
- long index)
- {
- FW_MScriptable* desiredObject = NULL;
- FW_CElementIterator* iter = NewElementIterator(ev, part, desiredClass);
- FW_VOLATILE(iter);
-
- FW_TRY
- {
- long count = 0;
-
- for (FW_MScriptable* currentObject = iter->First(); count <= index && iter->IsNotComplete();
- currentObject = iter->Next())
- {
- if (++count == index)
- desiredObject = currentObject;
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- delete iter;
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- delete iter;
-
- if (desiredObject)
- desiredObject->AcquireScriptable();
- return desiredObject;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetFirstElement
- //---------------------------------------------------------------------------------------
-
- FW_MScriptable* FW_MScriptable::GetFirstElement(Environment* ev,
- FW_CPart* part,
- ODDescType desiredClass)
- {
- return (GetElementByIndex(ev, part, desiredClass, 1));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetMiddleElement
- //---------------------------------------------------------------------------------------
-
- FW_MScriptable* FW_MScriptable::GetMiddleElement(Environment* ev,
- FW_CPart* part,
- ODDescType desiredClass)
- {
- return (GetElementByIndex(ev, part, desiredClass, (CountElements(ev, part, desiredClass) + 1) / 2));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetLastElement
- //---------------------------------------------------------------------------------------
-
- FW_MScriptable* FW_MScriptable::GetLastElement(Environment* ev,
- FW_CPart* part,
- ODDescType desiredClass)
- {
- return (GetElementByIndex(ev, part, desiredClass, CountElements(ev, part, desiredClass)));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetAnyElement
- //---------------------------------------------------------------------------------------
-
- FW_MScriptable* FW_MScriptable::GetAnyElement(Environment* ev,
- FW_CPart* part,
- ODDescType desiredClass)
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- FW_UNUSED(desiredClass);
- FW_PRIV_ASSERT(Not_Yet_Implemented);
- return NULL;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetAllElements
- //---------------------------------------------------------------------------------------
-
- FW_MScriptable* FW_MScriptable::GetAllElements(Environment* ev,
- FW_CPart* part,
- ODDescType desiredClass)
- {
- FW_CElementIterator* iter = NULL;
- FW_VOLATILE(iter);
- FW_CScriptableCollection* collection = NULL;
- FW_VOLATILE(collection);
-
- FW_TRY
- {
- iter = NewElementIterator(ev, part, desiredClass);
- collection = FW_NEW(FW_CScriptableCollection, ());
-
- for (FW_MScriptable* currentObject = iter->First(); iter->IsNotComplete();
- currentObject = iter->Next())
- {
- collection->Add(currentObject);
- }
- delete iter;
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- delete collection;
- delete iter;
-
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- if (collection->Count() == 0)
- {
- delete collection;
- collection = NULL;
- }
-
- return collection;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetAdjacentObject
- //---------------------------------------------------------------------------------------
-
- FW_MScriptable* FW_MScriptable::GetAdjacentObject(Environment* ev,
- FW_CPart* part,
- ODDescType desiredClass,
- ODDescType relativePosition) const
- {
- FW_MScriptable* result = NULL;
- FW_MScriptable* container = GetContainingObject(ev, part);
-
- if (container)
- {
- FW_CElementIterator* iter = container->NewElementIterator(ev, part, desiredClass);
- FW_VOLATILE(iter);
-
- FW_MScriptable* previous = NULL;
- FW_Boolean keepGoing = TRUE;
- FW_Boolean fetchNext = FALSE;
-
- FW_TRY
- {
- for (FW_MScriptable* currentObject = iter->First(); keepGoing && iter->IsNotComplete();
- currentObject = iter->Next())
- {
- if (fetchNext)
- {
- result = currentObject;
- keepGoing = FALSE;
- }
- else if (currentObject == this)
- {
- if (relativePosition == kAEPrevious)
- {
- result = previous;
- keepGoing = FALSE;
- }
- else
- fetchNext = TRUE;
- }
- previous = currentObject;
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- delete iter;
- FW_THROW_SAME();
- }
- FW_CATCH_END
- }
-
- if (result)
- result->AcquireScriptable();
- return result;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetElementsWithinRange
- //---------------------------------------------------------------------------------------
-
- FW_MScriptable* FW_MScriptable::GetElementsWithinRange(Environment* ev,
- FW_CPart* part,
- ODDescType desiredClass,
- FW_MScriptable* startObject,
- FW_MScriptable* stopObject) const
- {
- FW_CElementIterator* iter = NewElementIterator(ev, part, desiredClass);
- FW_CScriptableCollection* collection = FW_NEW(FW_CScriptableCollection, ());
-
- FW_Boolean foundStart = FALSE;
- FW_Boolean foundStop = FALSE;
-
- for (FW_MScriptable* currentObject = iter->First(); !foundStop && iter->IsNotComplete();
- currentObject = iter->Next())
- {
- FW_CDesc objectDesc;
-
- ::FW_InsertScriptableIntoDesc(currentObject, objectDesc);
-
- if (!foundStart)
- foundStart = startObject->CompareScriptableObjects(ev, part, kAEEquals, objectDesc);
-
- if (foundStart)
- collection->Add(currentObject);
-
- foundStop = stopObject->CompareScriptableObjects(ev, part, kAEEquals, objectDesc);
- }
-
- return collection;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::NewElementIterator
- //---------------------------------------------------------------------------------------
-
- FW_CElementIterator* FW_MScriptable::NewElementIterator(Environment* ev,
- FW_CPart* part,
- ODDescType desiredClass) const
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- FW_UNUSED(desiredClass);
- FW_THROW(FW_XException(errAEEventNotHandled));
- return NULL;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::HasProperty
- //---------------------------------------------------------------------------------------
-
- FW_Boolean FW_MScriptable::HasProperty(ODDescType whichProperty) const
- {
- return (whichProperty == pClass); // class is the only supported property
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::BuildObjectSpecifier
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::BuildObjectSpecifier(Environment* ev,
- FW_CPart* part,
- const FW_CFrame* frame,
- FW_CDesc& specifier,
- ODDescType preferredForm) const
- {
- FW_MScriptable* container = GetContainingObject(ev, part);
-
- FW_CDesc containerSpecifier;
- FW_CDesc mySpecifier;
- FW_Boolean gotData = FALSE;
-
- container->BuildObjectSpecifier(ev, part, frame, containerSpecifier, container->GetSpecifierForm());
-
- switch (preferredForm)
- {
- case formName:
- gotData = HasProperty(pName) && GetProperty(ev, part, mySpecifier, pName);
- break;
-
- case formUniqueID:
- gotData = HasProperty(pID) && GetProperty(ev, part, mySpecifier, pID);
- break;
-
- case formAbsolutePosition:
- gotData = HasProperty(pIndex) && GetProperty(ev, part, mySpecifier, pIndex);
- break;
-
- default:
- break;
- }
-
- if (!gotData)
- FW_THROW(FW_XException(errAECantSupplyType));
-
- ::FW_CreateObjSpecifier(GetObjectClass(), containerSpecifier, preferredForm, mySpecifier, specifier);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetObjectSpecifier
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::GetObjectSpecifier(Environment* ev,
- FW_CPart* part,
- FW_CDesc& specifier) const
- {
- BuildObjectSpecifier(ev, part, GetFrame(ev, part), specifier, GetSpecifierForm());
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetPropertySpecifier
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::GetPropertySpecifier(Environment* ev,
- FW_CPart* part,
- ODDescType whichProperty,
- FW_CDesc& specifier)
- {
- if (HasProperty(whichProperty))
- {
- FW_CDesc objectDesc;
- FW_CDesc propertyDesc;
-
- GetObjectSpecifier(ev, part, objectDesc);
- propertyDesc.PutType(whichProperty);
-
- ::FW_CreateObjSpecifier(cProperty, objectDesc, formPropertyID, propertyDesc, specifier);
- }
- else
- FW_THROW(FW_XException(errAENoSuchObject));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetPropertyInfo
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::GetPropertyInfo(Environment* ev,
- FW_CPart* part,
- FW_Boolean& canUndo,
- FW_Boolean& causesChange) const
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- canUndo = TRUE;
- causesChange = TRUE;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetProperty
- //---------------------------------------------------------------------------------------
-
- FW_Boolean FW_MScriptable::GetProperty(Environment* ev,
- FW_CPart* part,
- FW_CDesc& propertyValue,
- ODDescType whichProperty,
- ODDescType desiredClass) const
- {
- FW_UNUSED(desiredClass);
- FW_Boolean hasProperty = FALSE;
-
- switch (whichProperty)
- {
- case pClass:
- {
- ODDescType itsClass = GetObjectClass();
- propertyValue << itsClass;
- hasProperty = TRUE;
- }
- break;
-
- case pIndex:
- {
- FW_MScriptable* container = GetContainingObject(ev, part);
- FW_CElementIterator* iter = container->NewElementIterator(ev, part, GetObjectClass());
- FW_VOLATILE(iter);
-
- long index = 1;
-
- FW_TRY
- {
- for (FW_MScriptable* semObj = iter->First(); iter->IsNotComplete() && !hasProperty; semObj = iter->Next(), index++)
- {
- if (semObj == this)
- {
- propertyValue << index;
- hasProperty = TRUE;
- }
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- delete iter;
- FW_THROW_SAME();
- }
- FW_CATCH_END
- }
- break;
-
- default:
- hasProperty = FALSE;
- break;
- }
-
- return hasProperty;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::SetProperty
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::SetProperty(Environment* ev,
- FW_CPart* part,
- FW_CDesc& propertyValue,
- ODDescType whichProperty)
- {
- FW_UNUSED(ev);
- FW_UNUSED(part);
- FW_UNUSED(propertyValue);
- FW_UNUSED(whichProperty);
- FW_THROW(FW_XException(errAEEventNotHandled));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::SetProperties
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::SetProperties(Environment* ev,
- FW_CPart* part,
- const FW_CDesc& contents)
- {
- if (contents.IsRecord())
- {
- FW_CDesc value;
- long propertyCount = contents.GetItemCount();
- for (long index = 1; index <= propertyCount; index++)
- {
- ODDescType whichProperty;
- value.Clear();
- contents.GetDescFromList(index, whichProperty, value);
- SetProperty(ev, part, value, whichProperty);
- }
- }
- else
- FW_THROW(FW_XException(errAEEventNotHandled));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::SetProperties
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::SetProperties(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event)
- {
-
- if (event.HasDataKey(keyAEPropData))
- {
- FW_CDesc propertyList;
-
- event.GetDataByDesc(propertyList, keyAEPropData, typeAERecord);
- SetProperties(ev, part, propertyList);
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::RestoreProperty
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::RestoreProperty(Environment* ev,
- FW_CPart* part,
- FW_CDesc& propertyValue,
- ODDescType whichProperty)
- {
- this->SetProperty(ev, part, propertyValue, whichProperty);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::GetUndoSetPropertyStrings
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::GetUndoStrings(Environment* ev,
- FW_CPart* part,
- ODDescType whichProperty,
- FW_CString& undoString,
- FW_CString& redoString) const
- {
- FW_UNUSED(part);
- FW_UNUSED(whichProperty);
- // "Undo Set Property" and "Redo Set Property"
- // Subclasses can optionally override and provide more descriptive strings
- ::FW_PrivLoadUndoStrings(ev, FW_kUndoSetPropertyMsg, undoString, redoString);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::AddDependent
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::AddDependent(FW_MScriptable* dependent)
- {
- if (!fDependents)
- fDependents = FW_NEW(FW_TOrderedCollection<FW_MScriptable>, ());
- fDependents->AddFirst(dependent);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::RemoveDependent
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::RemoveDependent(FW_MScriptable* dependent)
- {
- FW_ASSERT(fDependents);
- fDependents->Remove(dependent);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_MScriptable::HandlePrimaryDeleted
- //---------------------------------------------------------------------------------------
-
- void FW_MScriptable::HandlePrimaryDeleted(FW_MScriptable* primary)
- {
- FW_UNUSED(primary);
- FW_DEBUG_MESSAGE("FW_MScriptable::HandlePrimaryDeleted should be handled by a derived class");
- }
-
- //========================================================================================
- // class FW_CElementIterator
- //========================================================================================
-
- //---------------------------------------------------------------------------------------
- // FW_CElementIterator::FW_CElementIterator
- //---------------------------------------------------------------------------------------
-
- FW_CElementIterator::FW_CElementIterator()
- {
- FW_END_CONSTRUCTOR
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CElementIterator::~FW_CElementIterator
- //---------------------------------------------------------------------------------------
-
- FW_CElementIterator::~FW_CElementIterator()
- {
- FW_START_DESTRUCTOR
- }
-